
package cn;

import java.util.Random;
import java.util.UUID;

public class RandomDemo {
    public static void main(String[] args) {
        //1.java.util.Random随机类
        Random rand = new Random();
        System.out.println(rand.nextBoolean());
        System.out.println(rand.nextInt());
        //0-5
        System.out.println(rand.nextInt(6));
        //6-9 java10之后才可以使用 0 - now(毫秒)
        System.out.println(rand.nextInt(6, 10));

        System.out.printf("%tF %<tT %n",0L);
        for (int i = 0; i < 5; i++) {
            System.out.printf("%tF %<tT %n", rand.nextLong(0, System.currentTimeMillis()));
        }


        //2.java.lang.Math 类的random()方法
        System.out.println("Math.random():0-1之间的随机double");
        for (int i = 0; i < 3; i++) {
            System.out.println(Math.random());
            //随机数 0 - 6
            System.out.println(Math.round(Math.random() * 6));
        }


        //3.java.util.UUID 类 唯一随机字符串36位十六进制的字符
        System.out.println("uuid - string:");
        for (int i = 0; i < 3; i++) {
            System.out.println(UUID.randomUUID().toString().toLowerCase());
        }
    }
}
